package gsw.tool.skin.utils;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by siwei on 2018/3/18.
 */

/**
 * 换肤首选项
 * 用来保存皮肤包的路径
 */
public class SkinPreference {
    private final String SKIN_SHARED = "skin";
    private final String SKIN_PATH = "skinPath";
    private final SharedPreferences sharedPreferences;
    private static SkinPreference skinPreference;

    private SkinPreference(Context context) {
        sharedPreferences = context.getSharedPreferences(SKIN_SHARED, Context.MODE_PRIVATE);
    }

    public static void init(Application application) {
        if (skinPreference == null) {
            synchronized (SkinPreference.class) {
                if (skinPreference == null) {
                    skinPreference = new SkinPreference(application);
                }
            }
        }
    }

    public static SkinPreference getInstance() {
        return skinPreference;
    }

    /**
     * 获取皮肤包路径
     *
     * @return
     */
    public String getSkin() {
        return sharedPreferences.getString(SKIN_PATH, null);
    }

    /**
     * 保存皮肤包路径
     *
     * @param skinPath
     */
    public void setSkin(String skinPath) {
        sharedPreferences.edit().putString(SKIN_PATH, skinPath).apply();
    }
}
